{% extends "base.html" %}

{% block title %}用户详情 - {{ user.username }}{% endblock %}

{% block content %}
<div class="row mb-4">
    <div class="col-12 d-flex justify-content-between align-items-center">
        <h2 class="mb-0"><i class="fas fa-user me-2"></i>用户详情</h2>
        <div>
            <a href="{{ url_for('user.list') }}" class="btn btn-secondary">
                <i class="fas fa-arrow-left me-1"></i>返回列表
            </a>
            <a href="{{ url_for('user.edit', user_id=user.user_id) }}" class="btn btn-primary ms-2">
                <i class="fas fa-edit me-1"></i>编辑
            </a>
        </div>
    </div>
</div>

<div class="row">
    <!-- 用户基本信息 -->
    <div class="col-md-4 mb-4">
        <div class="card shadow-sm h-100">
            <div class="card-body text-center">
                <div class="mb-3">
                    <div class="d-inline-block rounded-circle bg-primary text-white" style="width: 100px; height: 100px; line-height: 100px; font-size: 40px;">
                        {{ user.username[0].upper() if user.username else '?' }}
                    </div>
                </div>
                <h3 class="mb-2">{{ user.username }}</h3>
                <div class="mb-3">
                    <span class="badge bg-success mb-2">正常</span>
                </div>
                
                <div class="btn-group w-100">
                    <a href="{{ url_for('user.toggle_status', user_id=user.user_id) }}" class="btn btn-secondary" title="当前数据库不支持此功能">
                        <i class="fas fa-user-slash me-1"></i>
                        禁用(不可用)
                    </a>
                    <a href="{{ url_for('user.delete', user_id=user.user_id) }}" class="btn btn-danger btn-delete">
                        <i class="fas fa-trash me-1"></i>删除
                    </a>
                </div>
            </div>
        </div>
    </div>
    
    <!-- 用户详细信息 -->
    <div class="col-md-8">
        <div class="card shadow-sm mb-4">
            <div class="card-header bg-light">
                <h5 class="mb-0"><i class="fas fa-info-circle me-2"></i>基本信息</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">用户ID</h6>
                        <p>{{ user.user_id }}</p>
                    </div>
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">用户名</h6>
                        <p>{{ user.username }}</p>
                    </div>
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">姓名</h6>
                        <p>{{ user.full_name or '未设置' }}</p>
                    </div>
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">邮箱</h6>
                        <p>{{ user.email or '未设置' }}</p>
                    </div>
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">电话</h6>
                        <p>{{ user.phone or '未设置' }}</p>
                    </div>
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">用户类型</h6>
                        <p>
                            {% if user.is_admin %}
                            <span class="badge bg-danger">管理员</span>
                            {% else %}
                            <span class="badge bg-info">普通用户</span>
                            {% endif %}
                        </p>
                    </div>
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">注册时间</h6>
                        <p>{{ user.create_time.strftime('%Y-%m-%d %H:%M:%S') if user.create_time else '未知' }}</p>
                    </div>
                    <div class="col-md-6 mb-3">
                        <h6 class="text-muted">最后登录</h6>
                        <p>{{ user.last_login.strftime('%Y-%m-%d %H:%M:%S') if user.last_login else '未登录' }}</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 用户订单列表 -->
<div class="row mt-4">
    <div class="col-12 mb-4">
        <div class="card shadow-sm">
            <div class="card-header bg-light d-flex justify-content-between align-items-center">
                <h5 class="mb-0"><i class="fas fa-shopping-cart me-2"></i>用户订单</h5>
            </div>
            <div class="card-body">
                {% if orders %}
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th scope="col">#</th>
                                <th scope="col">订单编号</th>
                                <th scope="col">超市</th>
                                <th scope="col">金额</th>
                                <th scope="col">下单时间</th>
                                <th scope="col">状态</th>
                                <th scope="col">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for order in orders %}
                            <tr>
                                <td>{{ order.order_id }}</td>
                                <td>{{ order.order_no }}</td>
                                <td>{{ order.supermarket.name if order.supermarket else '未知' }}</td>
                                <td><span class="text-danger">¥{{ "%.2f"|format(order.total_amount) }}</span></td>
                                <td>{{ order.create_time.strftime('%Y-%m-%d %H:%M:%S') if order.create_time else '未知' }}</td>
                                <td>
                                    {% if order.status == 0 %}
                                    <span class="badge bg-warning text-dark">待支付</span>
                                    {% elif order.status == 1 %}
                                    <span class="badge bg-info">已支付</span>
                                    {% elif order.status == 2 %}
                                    <span class="badge bg-danger">已取消</span>
                                    {% elif order.status == 3 %}
                                    <span class="badge bg-success">已完成</span>
                                    {% else %}
                                    <span class="badge bg-secondary">未知状态</span>
                                    {% endif %}
                                </td>
                                <td>
                                    <a href="{{ url_for('order.detail', order_id=order.order_id) }}" class="btn btn-sm btn-info">
                                        <i class="fas fa-info-circle"></i>
                                    </a>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                {% else %}
                <div class="text-center py-4 text-muted">
                    <i class="fas fa-shopping-cart fa-3x mb-3"></i>
                    <p>该用户暂无订单记录</p>
                </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}
